package com.acme.bankapp.domain.client;

import com.acme.bankapp.domain.bank.Account;
import com.acme.bankapp.domain.bank.CheckingAccount;
import com.acme.bankapp.domain.bank.Client;
import com.acme.bankapp.domain.bank.SavingAccount;

public class ClientFactory {

    public static Client createClient(
	    final ClientInfoProvider clientInfoProvider) {

	Account account;

	switch (clientInfoProvider.getAccountType()) {
	case CHECKING:
	    account = new CheckingAccount(clientInfoProvider.getAccountId(),
		    clientInfoProvider.getBalance(),
		    clientInfoProvider.getOverdraft());
	    break;
	case SAVING:
	    account = new SavingAccount(clientInfoProvider.getAccountId(),
		    clientInfoProvider.getBalance());
	    break;
	default:
	    throw new IllegalArgumentException(
		    "ClientInfoProvider has unknown AccountType");
	}

	return new Client(clientInfoProvider.getClientName(),
		clientInfoProvider.getClientGender(), account);
    }
}
